// Package sys
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2024 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.13.1
package sys

import (
	"context"
	"hotgo/api/admin/stockzhaspotem"
	"hotgo/internal/dao"
	"hotgo/internal/model/input/sysin"
	"hotgo/internal/service"
	"hotgo/utility/tradeDate"
)

var (
	StockZhASpotEm = cStockZhASpotEm{}
)

type cStockZhASpotEm struct{}

// List 查看每日股票数据-东财1列表
func (c *cStockZhASpotEm) Statics(ctx context.Context, req *stockzhaspotem.StaticReq) (res *stockzhaspotem.StaticRes, err error) {
	resp, err := service.SysStockZhASpotEm().Statics(ctx)
	if err != nil {
		return
	}
	if resp == nil {
		resp = &sysin.StockZhASpotStatics{}
	}
	var ztCount = 0
	var dtCount = 0
	ztCount, _ = service.SysStockZtPool().Model(ctx).
		WhereGT(dao.StockZtPool.Columns().ChangePercent, 0).
		Where(dao.StockZtPool.Columns().Date, tradeDate.GetLatestDay()).
		Count()
	dtCount, _ = service.SysStockZtPool().Model(ctx).
		WhereLT(dao.StockZtPool.Columns().ChangePercent, 0).
		Where(dao.StockZtPool.Columns().Date, tradeDate.GetLatestDay()).
		Count()
	resp.ZtCount = ztCount
	resp.DtCount = dtCount
	res = new(stockzhaspotem.StaticRes)
	res.Data = resp
	return
}

//// List 查看每日股票数据-东财1列表
//func (c *cStockZhASpotEm) List(ctx context.Context, req *stockzhaspotem.ListReq) (res *stockzhaspotem.ListRes, err error) {
//	list, totalCount, err := service.SysStockZhASpotEm().List(ctx, &req.StockZhASpotEmListInp)
//	if err != nil {
//		return
//	}
//
//	if list == nil {
//		list = []*sysin.StockZhASpotEmListModel{}
//	}
//
//	res = new(stockzhaspotem.ListRes)
//	res.List = list
//	res.PageRes.Pack(req, totalCount)
//	return
//}

// List 查看每日股票数据-东财1列表
func (c *cStockZhASpotEm) List(ctx context.Context, req *stockzhaspotem.ListReq) (res *stockzhaspotem.ListRes, err error) {
	list, totalCount, err := service.SysStockZhASpotEm().List(ctx, &req.StockZhASpotEmListInp)
	if err != nil {
		return
	}

	if list == nil {
		list = []*sysin.StockZhASpotEmListModel{}
	}

	res = new(stockzhaspotem.ListRes)
	res.List = list
	res.PageRes.Pack(req, totalCount)
	return
}

// Export 导出每日股票数据-东财1列表
func (c *cStockZhASpotEm) Export(ctx context.Context, req *stockzhaspotem.ExportReq) (res *stockzhaspotem.ExportRes, err error) {
	err = service.SysStockZhASpotEm().Export(ctx, &req.StockZhASpotEmListInp)
	return
}

// Edit 更新每日股票数据-东财1
func (c *cStockZhASpotEm) Edit(ctx context.Context, req *stockzhaspotem.EditReq) (res *stockzhaspotem.EditRes, err error) {
	err = service.SysStockZhASpotEm().Edit(ctx, &req.StockZhASpotEmEditInp)
	return
}

// View 获取指定每日股票数据-东财1信息
func (c *cStockZhASpotEm) View(ctx context.Context, req *stockzhaspotem.ViewReq) (res *stockzhaspotem.ViewRes, err error) {
	data, err := service.SysStockZhASpotEm().View(ctx, &req.StockZhASpotEmViewInp)
	if err != nil {
		return
	}

	res = new(stockzhaspotem.ViewRes)
	res.StockZhASpotEmViewModel = data
	return
}

// Delete 删除每日股票数据-东财1
func (c *cStockZhASpotEm) Delete(ctx context.Context, req *stockzhaspotem.DeleteReq) (res *stockzhaspotem.DeleteRes, err error) {
	err = service.SysStockZhASpotEm().Delete(ctx, &req.StockZhASpotEmDeleteInp)
	return
}
